﻿package view.expball
{
    import com.greensock.*;
    import com.sh.game.display.*;
    import com.sh.game.global.*;
    import flash.display.*;
    import morn.core.handlers.*;
    import view.uilt.*;

    public class ExpBallMagic extends Object
    {
        private var _con:Sprite;
        private var _panelmc:XMLMovieClip;
        private var _expballmc:XMLMovieClip;
        private var _ballboobmc:XMLMovieClip;
        public var _numItemCon:NumItemCon;
        private var _box1:Sprite;
        private var _load:int = 0;
        private var _panelH:int = 300;
        private var _panelW:int = 300;
        private var _func:Function;
        private var _closenum:Boolean;
        private var _playLock:Boolean = false;
        private var _numbackfunc:Function;
        private var ballx:int;
        private var bally:int;
        public static var ballboob:Class = ExpBallMagic_ballboob;
        public static var expball:Class = ExpBallMagic_expball;
        public static var panelmc:Class = ExpBallMagic_panelmc;

        public function ExpBallMagic(param1:Sprite, param2:Function, param3:Function = null)
        {
            this.ballx = this._panelW / 2 - 300 / 2;
            this.bally = this._panelH / 2 - 300 / 2;
            this._con = param1;
            var _loc_4:String = "assets/images/mainui/expball.swf";
            this._func = param2;
            this._numbackfunc = param3;
            this._load = 1;
            App.leisureMloader.loadSWF(Config.getUrl(_loc_4), 3, new Handler(this.onCompitemeffect));
            return;
        }// end function

        private function onCompitemeffect(param1:Object) : void
        {
            this._load = 2;
            this.initView();
            return;
        }// end function

        public function initView() : void
        {
            this._box1 = new Sprite();
            this._con.addChild(this._box1);
            this._panelmc = new XMLMovieClip("png.ball.panelmc", new XML(new panelmc()));
            this._box1.addChild(this._panelmc);
            this._panelmc.interval = 1000 / 15;
            var _loc_1:* = new Sprite();
            this._box1.addChild(_loc_1);
            _loc_1.y = 170;
            if (this._numbackfunc == null)
            {
                this._numItemCon = new NumItemCon(_loc_1, this.numover);
            }
            else
            {
                this._numItemCon = new NumItemCon(_loc_1, this._numbackfunc);
            }
            this._numItemCon.parentW = 300;
            this._con.visible = false;
            return;
        }// end function

        private function numover() : void
        {
            if (this._expballmc == null)
            {
                this._expballmc = new XMLMovieClip("png.ball.expball", new XML(new expball()));
                this._con.addChild(this._expballmc);
                this._expballmc.blendMode = BlendMode.ADD;
                this._expballmc.x = this.ballx;
                this._expballmc.y = this.bally;
                this._expballmc.interval = 1000 / 15;
            }
            else
            {
                this._expballmc.visible = true;
            }
            this._expballmc.alpha = 0;
            this._expballmc.scaleX = 0.5;
            this._expballmc.scaleY = 0.5;
            this._expballmc.x = this._panelW / 2 - 300 / 4;
            this._expballmc.y = this._panelH / 2 - 300 / 4;
            TweenLite.to(this._expballmc, 0.2, {delay:1.5, scaleX:1, scaleY:1, x:this.ballx, y:this.bally, alpha:1});
            TweenLite.to(this._box1, 0.2, {alpha:0, delay:1.5, scaleX:0, scaleY:0, x:this._panelW / 2, y:this._panelH / 2, onComplete:this.comScaleFunc});
            return;
        }// end function

        private function comScaleFunc() : void
        {
            TweenLite.to(this._expballmc, 0.35, {x:ItemUilt.ExpPoint.x - this._con.x - 300 / 2, y:ItemUilt.ExpPoint.y - this._con.y - 300 / 2, onComplete:this.comBoobFunc});
            return;
        }// end function

        private function comBoobFunc() : void
        {
            this._expballmc.visible = false;
            if (this._ballboobmc == null)
            {
                this._ballboobmc = new XMLMovieClip("png.ball.ballboob", new XML(new ballboob()));
                this._con.addChild(this._ballboobmc);
                this._ballboobmc.interval = 1000 / 15;
            }
            else
            {
                this._ballboobmc.visible = true;
            }
            this._ballboobmc.x = ItemUilt.ExpPoint.x - this._con.x - 300 / 2;
            this._ballboobmc.y = ItemUilt.ExpPoint.y - this._con.y - 300 / 2;
            this._ballboobmc.playFromTo(-1, (this._ballboobmc.totalFrame - 1), new Handler(this.onComplete));
            return;
        }// end function

        public function playnum(param1:int) : void
        {
            if (this._playLock)
            {
                return;
            }
            if (param1 <= 0)
            {
                return;
            }
            this._numItemCon.playNum(param1);
            return;
        }// end function

        public function playMovie(param1:int) : void
        {
            if (this._load != 2 || this._playLock)
            {
                if (this._func != null)
                {
                    this._func();
                }
                return;
            }
            if (param1 == 0)
            {
                return;
            }
            this.clearplay();
            this._playLock = true;
            this._con.visible = true;
            this._numItemCon.playNum(param1);
            return;
        }// end function

        private function onComplete() : void
        {
            if (this._func != null)
            {
                this._func();
            }
            this.clearplay();
            return;
        }// end function

        public function clearplay() : void
        {
            this._playLock = false;
            this._con.visible = false;
            this._box1.visible = true;
            this._box1.scaleX = 1;
            this._box1.scaleY = 1;
            this._box1.x = 0;
            this._box1.y = 0;
            this._box1.alpha = 1;
            this._numItemCon.clear();
            return;
        }// end function

        public function despose() : void
        {
            return;
        }// end function

    }
}
